Zip Utils
The ZipUtils class is part of the @promaton/scan-viewer package and provides high-level utility functions for working with zip archives. It allows you to extract, inspect, and create zip files using the zip.js library.
Constructors
new ZipUtils()
Creates a new instance of the ZipUtils class.
Returns
ZipUtils: A new instance of theZipUtilsclass.
Methods
getZipEntries()
Retrieves a list of all files and directories in a zip archive without unpacking them.
Signature
static getZipEntries(data: Blob, password?: string): Promise<Entry[]>
Parameters
data(Blob): The zip file to inspect.password?(string): Optional password for encrypted zip files.
Returns
Promise<Entry[]>: A promise that resolves to an array of entries (files and directories) in the zip archive.
unpackZip()
Unpacks a zip archive into a list of files, excluding files that match the specified ignore pattern.
Signature
static unpackZip(data: Blob, password?: string, ignorePattern?: RegExp): Promise<File[]>
Parameters
data(Blob): The zip file to unpack.password?(string): Optional password for encrypted zip files.ignorePattern?(RegExp): A regular expression to exclude certain files (default:fileIgnoreRegex).
Returns
Promise<File[]>: A promise that resolves to an array of unpacked files.
unpackZipEntry()
Unpacks a single entry from a zip archive into a blob.
Signature
static unpackZipEntry(entry: Entry, ignorePattern: RegExp): Promise<undefined | File>
Parameters
entry(Entry): The zip entry to unpack.ignorePattern(RegExp): A regular expression to exclude certain files (default:fileIgnoreRegex).
Returns
Promise<undefined | File>: A promise that resolves to the unpacked file orundefinedif the entry is ignored.
writeZip()
Creates a zip file from a given set of files.
Signature
static writeZip(files: File[]): Promise<Blob>
Parameters
files(File[]): An array of files to include in the zip archive.
Returns
Promise<Blob>: A promise that resolves to the created zip file as a blob.
The ZipUtils class simplifies working with zip archives, making it easy to inspect, extract, and create zip files programmatically.